

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        nextId: 0,
        List: JSON.parse(localStorage.getItem('Glist')) || [],
        id:null,
        show: false,
        dialogId: 0,
        songInfo: {},
        lyric: {},// 歌词枚举对象(需要在js拿到歌词写代码处理后, 按照格式保存到这个对象)
        curLyric: "", // 当前显示哪句歌词
        lastLy: "", // 记录当前播放歌词
        playState: false,//留声机是否旋转
        AplayState: 0,//留声机是否旋转
        sumTime: '00:00',
        nowTime: '00:00',
        nowTimePercentage: '',
        Progress: null,
        duration: '',//总时长秒速
        playIf: true,
        playNum:0,//每首歌,点击播放
        
    },
    mutations: {
        // 下一曲
        nextId(state, v) {
            let index = state.List.findIndex(item => item.id === parseInt(v))
            state.nextId = state.List[index + 1] === undefined ? state.List[0].id : state.List[index + 1].id
            state.id = state.nextId
            state.playNum++
        },
        // 上一曲preveId
        preveId(state, v) {
            let index = state.List.findIndex(item => item.id === parseInt(v))
            state.nextId = state.List[index - 1] === undefined ? state.List[0].id : state.List[index - 1].id
            state.id = state.nextId
            state.playNum++
        },
        setList(state, v) {
            state.List = v
            localStorage.setItem('Glist', JSON.stringify(v))
        },
        del (state, v) {
            state.List = state.List.filter(item => item.id != parseInt(v))
            localStorage.setItem('Glist', JSON.stringify(state.List))
        },
        deitShow (state,v) {state.show=v},
        // 歌单id
        deitDialogId (state, v) {state.dialogId=v },
        setSongInfo (state, v) {state.songInfo=v},
        setLyric (state, v) { state.lyric = v },
        setCurLyric (state, v) { state.curLyric = v },
        setLastLy (state, v) { state.lastLy = v },
        setPlayState (state, v) { state.playState = v },
        setAplayState (state) { state.AplayState++},
        setSumTime(state, v){state.sumTime=v},
        setNowTime(state, v){state.nowTime=v},
        setNowTimePercentage (state, v) { state.nowTimePercentage = v },
        setProgress(state, v){state.Progress = v},
        setDuration (state, v) { state.duration = v },
        setId (state, v) {state.id = v},
        setPlayNum (state) {state.playNum++},
      
    }
})
export default store